package com.example.service_vod.controller;

import com.example.common.commonsutils.R;
import com.example.common.exception.GuliException;
import com.example.service_vod.service.VodService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author:tjf
 * @Description:
 */
@RestController
@Tag(name = "视频控制器")
@RequestMapping("/vodservice")
public class VodController {
    @Resource
    private VodService vodService;

    @Operation(description = "上传视频")
    @PostMapping(value = "/", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R uploadVideo(@RequestPart MultipartFile file) {
        String videoId = vodService.uploadVideo(file);
        return R.ok().data("videoId", videoId);
    }

    @Operation(description = "根据视频id，删除已上传的视频")
    @DeleteMapping("/{videoId}")
    public R removeVideoById(@PathVariable("videoId") String videoId) {
        vodService.removeVideoById(videoId);
        return R.ok();
    }

    @Operation(description = "根据视频id，获取视频的播放凭证")
    @GetMapping("/{vSourceId}")
    public R fetchVideoPlayAuthByVSourceId(@PathVariable("vSourceId") String vSourceId) {
        String playAuth = vodService.fetchVideoPlayAuth(vSourceId);
        return R.ok().data("playAuth", playAuth);
    }
}
